package top.lshaci.learning.oauth2.server.controller;

import com.nimbusds.jose.jwk.JWKSet;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * PublicKeyController
 *
 * @author lshaci
 * @since 1.0.0
 */
@Slf4j
@RestController
@RequestMapping
@AllArgsConstructor
public class PublicKeyController {

    private final JWKSet jwkSet;

    /**
     * spring cloud gateway 需要获取 JWKSet 类型的公钥
     *
     * @return JWKSet 类型的公钥
     */
    @GetMapping("/publicKey")
    public Map<String, Object> publicKey() {
        return jwkSet.toJSONObject();
    }

}
